Skip to main content

<internal>

Index

Classes

ESComplex

ESComplex:

Next generation code complexity reporting for Javascript abstract syntax trees (AST). ESComplex exposes all methods available via ESComplexModule &amp; ESComplexProject modules which process AST. Several methods available below accept source code which is translated via Babel Parser w/ all plugins enabled allowing any ES6/ES7/edge JS and Typescript to be parsed. Asynchronous versions with the Async suffix of all methods are available as well.

@see

constructor

  • new ESComplex(options?: { module: { loadDefaultPlugins: boolean; plugins: any[] }; project: { loadDefaultPlugins: boolean; plugins: any[] } }): ESComplex
  • Initializes ESComplex.


    Parameters

    • options: { module: { loadDefaultPlugins: boolean; plugins: any[] }; project: { loadDefaultPlugins: boolean; plugins: any[] } } = ...

      module and project options including user plugins to load including:

      (object)             module - Provides an object hash of the following options for the module runtime:
      (boolean) loadDefaultPlugins - When false ESComplexModule will not load any default plugins.
      (Array<Object>) plugins - A list of ESComplexModule plugins that have already been instantiated.

      (object) project - Provides an object hash of the following options for the project runtime:
      (boolean) loadDefaultPlugins - When false ESComplexProject will not load any default plugins.
      (Array<Object>) plugins - A list of ESComplexProject plugins that have already been instantiated.

    Returns ESComplex

analyzeModule

  • analyzeModule(source: string, options?: ComplexityReporterOptions, parserOptions?: any, parserOverride?: any): default
  • Parses the given source code then processes the generated AST and calculates metrics via plugins.


    Parameters

    • source: string

      Javascript source code.

    • options: ComplexityReporterOptions = DefaultComplexityReporterOptions

      Module analyze options.

    • parserOptions: any = ...

      Overrides default Babel parser options.

    • parserOverride: any = ...

      Provides helper directives to override options to simplify modification of default Babel parser options.

    Returns default

    • A single module report.

analyzeModuleAST

  • analyzeModuleAST(ast: any, options: ComplexityReporterOptions): default
  • Processes the given ast and calculates metrics via plugins.


    Parameters

    • ast: any

      Javascript AST.

    • options: ComplexityReporterOptions

      Module analyze options.

    Returns default

    • A single module report.

analyzeModuleASTAsync

  • analyzeModuleASTAsync(ast: any, options: ComplexityReporterOptions): Promise<unknown>
  • Wraps in a Promise processing the given ast and calculates metrics via plugins.


    Parameters

    • ast: any

      Javascript AST.

    • options: ComplexityReporterOptions

      Module analyze options.

    Returns Promise<unknown>

    • A single module report.

analyzeModuleAsync

  • analyzeModuleAsync(source: string, options: ComplexityReporterOptions, parserOptions?: any, parserOverride?: any): Promise<unknown>
  • Wraps in a Promise parsing of the given source code then processes the generated AST and calculates metrics via plugins.


    Parameters

    • source: string

      Javascript source code.

    • options: ComplexityReporterOptions

      Module analyze options.

    • parserOptions: any = ...

      Overrides default babylon parser options.

    • parserOverride: any = ...

      Provides helper directives to override options to simplify modification of default Babel parser options.

    Returns Promise<unknown>

    • A single module report.

analyzeProject

  • analyzeProject(sources: any[], options?: any, parserOptions?: any, parserOverride?: any): any
  • Processes the given sources and calculates project metrics via plugins.


    Parameters

    • sources: any[]

      Array of object hashes containing code and srcPath entries with optional entries include filePath and srcPathAlias.

    • options: any = {}

      Project processing options.

    • parserOptions: any = ...

      Overrides default Babel parser options.

    • parserOverride: any = ...

      Provides helper directives to override options to simplify modification of default Babel parser options.

    Returns any

    • An object hash with a reports entry that is an Array of module results.

analyzeProjectAST

  • analyzeProjectAST(modules: any[], options: any): any
  • Processes the given modules and calculates project metrics via plugins.


    Parameters

    • modules: any[]

      Array of object hashes containing ast and srcPath entries with optional entries include filePath and srcPathAlias.

    • options: any

      (Optional) project processing options.

    Returns any

    • An object hash with a reports entry that is an Array of module results.

analyzeProjectASTAsync

  • analyzeProjectASTAsync(modules: any[], options: ProjectOptions): Promise<unknown>
  • Wraps in a Promise processing the given modules and calculates project metrics via plugins.


    Parameters

    • modules: any[]

      Array of object hashes containing ast and path entries.

    • options: ProjectOptions

      Project processing options.

    Returns Promise<unknown>

    • An object hash with a reports entry that is an Array of module results.

analyzeProjectAsync

  • analyzeProjectAsync(sources: any[], options?: {}, parserOptions?: any, parserOverride?: any): Promise<unknown>
  • Wraps in a Promise processing the given sources and calculates project metrics via plugins.


    Parameters

    • sources: any[]

      Array of object hashes containing code and path entries.

    • options: {} = {}

      Project processing options.

    • parserOptions: any = ...

      Overrides default babylon parser options.

    • parserOverride: any = ...

      Provides helper directives to override options to simplify modification of default Babel parser options.

    Returns Promise<unknown>

    • An object hash with a reports entry that is an Array of module results.

parse

  • parse(source: string, parserOptions?: any, parserOverride?: any): ParseResult<File>
  • Provides a convenience method to parse the given source code and return the Babel parser AST.


    Parameters

    • source: string

      Javascript source code.

    • parserOptions: any = ...

      Overrides default babylon parser options.

    • parserOverride: any = ...

      Provides helper directives to override options to simplify modification of default Babel parser options.

    Returns ParseResult<File>

    • babylon generated AST.

parseAsync

  • parseAsync(source: string, parserOptions?: any, parserOverride?: any): Promise<unknown>
  • Wraps in a Promise a convenience method to parse the given source code and return the babylon AST.


    Parameters

    • source: string

      Javascript source code.

    • parserOptions: any = ...

      Overrides default babylon parser options.

    • parserOverride: any = ...

      Provides helper directives to override options to simplify modification of default Babel parser options.

    Returns Promise<unknown>

    • babylon generated AST.

processProject

  • processProject(results: any, options?: {}): any
  • Processes existing project results and calculates metrics via plugins.


    Parameters

    • results: any

      An object hash with a reports entry that is an Array of module results.

    • options: {} = {}

      (Optional) project processing options.

    Returns any

    • An object hash with a reports entry that is an Array of module results.

processProjectAsync

  • processProjectAsync(results: any, options?: {}): Promise<unknown>
  • Wraps in a Promise processing existing project results and calculates metrics via plugins.


    Parameters

    • results: any

      An object hash with a reports entry that is an Array of module results.

    • options: {} = {}

      (Optional) project processing options.

    Returns Promise<unknown>

    • An object hash with a reports entry that is an Array of module results.

default

default:

Provides a runtime to invoke ESComplexProject plugins for processing / metrics calculations of projects.

constructor

  • new default(pathModule: PlatformPath, options?: ProjectOptions): default
  • Initializes ESComplexProject.

    @see

    Parameters

    • pathModule: PlatformPath

      Provides an object which matches the Node path module. In particular the following entries must be provided:

      (string)    sep - Provides the platform-specific path segment separator: `/` on POSIX & `\` on Windows.

      (function) dirname - Returns the directory name of a path, similar to the Unix dirname command.

      (function) extname - Returns the extension of the path, from the last occurance of the . (period) character to
      end of string in the last portion of the path.

      (function) relative - Returns the relative path from from to to.

      (function) resolve - Resolves a sequence of paths or path segments into an absolute path.
    • optionaloptions: ProjectOptions

      module and project options including user plugins to load including:

      (object)             module - Provides an object hash of the following options for the module runtime:
      (boolean) loadDefaultPlugins - When false ESComplexModule will not load any default plugins.
      (Array<Object>) plugins - A list of ESComplexModule plugins that have already been instantiated.

      (object) project - Provides an object hash of the following options for the project runtime:
      (boolean) loadDefaultPlugins - When false ESComplexProject will not load any default plugins.
      (Array<Object>) plugins - A list of ESComplexProject plugins that have already been instantiated.

    Returns default

analyze

  • analyze(modules: any[], options?: ComplexityReporterOptions): any
  • Processes the given modules and calculates project metrics via plugins.


    Parameters

    • modules: any[]

      Array of object hashes containing ast and srcPath entries. Optionally srcPathAlias and filePath entries may also be provided.

    • optionaloptions: ComplexityReporterOptions

      (Optional) project processing options.

    Returns any

analyzeAsync

  • analyzeAsync(modules: any[], options?: {}): Promise<unknown>
  • Wraps in a Promise processing the given modules and calculates metrics via plugins.


    Parameters

    • modules: any[]

      Array of object hashes containing ast and srcPath entries. Optionally srcPathAlias and filePath entries may also be provided.

    • optionaloptions: {}

      project processing options

    Returns Promise<unknown>

process

  • process(projectReport: default, options?: {}): any
  • Processes an existing ProjectReport instance and calculates metrics via plugins.


    Parameters

    • projectReport: default

      An instance of ProjectReport with a modules entry that is an Array of ModuleReports.

    • optionaloptions: {}

      (Optional) project processing options.

    Returns any

processAsync

  • processAsync(projectReport: default, options?: {}): Promise<unknown>
  • Wraps in a Promise processing of existing ProjectReport instance and calculates metrics via plugins.


    Parameters

    • projectReport: default

      An instance of ProjectReport.

    • optionaloptions: {}

      (Optional) project processing options.

    Returns Promise<unknown>

Interfaces

ComplexityReporterOptions

ComplexityReporterOptions:

optionalecmaFeatures

ecmaFeatures?: EcmaFeatures

ecmaVersion

ecmaVersion: number

loc

loc: boolean

newmi

newmi: boolean

optionalparserOptions

parserOptions?: ParserOptions

range

range: boolean

sourceType

sourceType: string

EcmaFeatures

EcmaFeatures:

optionalarrowFunctions

arrowFunctions?: boolean

optionalbinaryLiterals

binaryLiterals?: boolean

optionalblockBindings

blockBindings?: boolean

optionalclasses

classes?: boolean

optionaldefaultParams

defaultParams?: boolean

optionaldestructuring

destructuring?: boolean

optionalexperimentalObjectRestSpread

experimentalObjectRestSpread?: boolean

optionalforOf

forOf?: boolean

optionalgenerators

generators?: boolean

optionalglobalReturn

globalReturn?: boolean

optionaljsx

jsx?: boolean

optionalmodules

modules?: boolean

optionalobjectLiteralComputedProperties

objectLiteralComputedProperties?: boolean

optionalobjectLiteralDuplicateProperties

objectLiteralDuplicateProperties?: boolean

optionalobjectLiteralShorthandMethods

objectLiteralShorthandMethods?: boolean

optionalobjectLiteralShorthandProperties

objectLiteralShorthandProperties?: boolean

optionaloctalLiterals

octalLiterals?: boolean

optionalregexUFlag

regexUFlag?: boolean

optionalregexYFlag

regexYFlag?: boolean

optionalrestParams

restParams?: boolean

optionalspread

spread?: boolean

optionaltemplateStrings

templateStrings?: boolean

optionaltypescript

typescript?: boolean

optionalunicodeCodePointEscapes

unicodeCodePointEscapes?: boolean

ParserOptions

ParserOptions:

optionalbabelOptions

babelOptions?: object

ecmaFeatures

ecmaFeatures: EcmaFeatures

sourceType

sourceType: string

Plugin

Plugin:

onConfigure

  • onConfigure(options: ComplexityReporterOptions[]): any
  • Parameters

    • options: ComplexityReporterOptions[]

    Returns any

onProjectAverage

  • onProjectAverage(projectReport: any, pathModule: PlatformPath, settings: any): any
  • Parameters

    • projectReport: any
    • pathModule: PlatformPath
    • settings: any

    Returns any

onProjectCalculate

  • onProjectCalculate(projectReport: any, pathModule: PlatformPath, settings: any): any
  • Parameters

    • projectReport: any
    • pathModule: PlatformPath
    • settings: any

    Returns any

onProjectEnd

  • onProjectEnd(projectReport: any, pathModule: PlatformPath, settings: any): any
  • Parameters

    • projectReport: any
    • pathModule: PlatformPath
    • settings: any

    Returns any

onProjectPostAverage

  • onProjectPostAverage(projectReport: any, pathModule: PlatformPath, settings: any): any
  • Parameters

    • projectReport: any
    • pathModule: PlatformPath
    • settings: any

    Returns any

onProjectStart

  • onProjectStart(projectReport: any, pathModule: PlatformPath, settings: any): any
  • Parameters

    • projectReport: any
    • pathModule: PlatformPath
    • settings: any

    Returns any

PluginOptions

PluginOptions:

loadDefaultPlugins

loadDefaultPlugins: boolean

plugins

plugins: Plugin[]

ProjectOptions

ProjectOptions:

module

module: PluginOptions

project

project: PluginOptions